package d0327;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.HashMap;
import java.util.Map;

public class WordCount {
    public static void main(String[] args) throws Exception {
        File fl=new File("src/d0327/b.txt");
        FileReader fr=new FileReader(fl);
        BufferedReader br=new BufferedReader(fr);
        Map<String,Integer> map=new HashMap<>();
        String str=null;
        //StringBuilder sb=new StringBuilder();
        while ((str=br.readLine())!=null) {
            String words[] = str.split("[ \n,.]");
            for (String word :
                    words) {
                if (word.equals("")) {
                    continue;
                }
                if (map.get(word) == null) {
                    map.put(word, 1);
                } else {
                    int oldValue = map.get(word);
                    map.put(word, oldValue + 1);
                }
            }
        }
        map.forEach ( (k,v)-> System.out.println (k+"\t"+v ) );
    }
}
